//
//  BCAlertModePickerViewController.m
//  Memo
//
//  Created by bonc on 13-9-10.
//  Copyright (c) 2013年 fuzhengbang. All rights reserved.
//

#import "BCAlertModePickerViewController.h"

@interface BCAlertModePickerViewController ()
@property (strong,nonatomic) UITableView* mytable;
@end

@implementation BCAlertModePickerViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
        self.title=@"提醒方式";
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.navigationItem.leftBarButtonItem=[[UIBarButtonItem alloc]initWithTitle:@"完成" style:UIBarButtonItemStylePlain target:self action:@selector(done)];
    self.navigationItem.rightBarButtonItem=[[UIBarButtonItem alloc]initWithTitle:@"取消" style:UIBarButtonItemStylePlain target:self action:@selector(cancle)];
//    if (IOS_VERSION_Above_7_0) {
//        self.edgesForExtendedLayout=UIRectEdgeNone;
//    }
    
    self.mytable=[[UITableView alloc]initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height-44) style:UITableViewStyleGrouped];
    self.mytable.delegate=self;
    self.mytable.dataSource=self;
    [self.view addSubview:self.mytable];
    
	// Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
#pragma mark -
#pragma mark TableView Delegate Method and TableView DataSource Method

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 4;
}

-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString* identifier=@"AlertCell";
    UITableViewCell* cell=[tableView dequeueReusableCellWithIdentifier:identifier];
    cell.accessoryType=UITableViewCellAccessoryNone;
    
    if (!cell) {
        cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
    }
    
    if (indexPath.row==0) {
        cell.textLabel.text=@"响铃";
        cell.selectionStyle=UITableViewCellSelectionStyleNone;
    }else if (indexPath.row==1){
        cell.textLabel.text=@"震动";
        cell.selectionStyle=UITableViewCellSelectionStyleNone;
    }else if (indexPath.row==2){
        cell.textLabel.text=@"静音";
        cell.selectionStyle=UITableViewCellSelectionStyleNone;
    }else {
        cell.textLabel.text=@"自定义铃声";
        cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;
    }
    
    if (indexPath.row==self.selectedMode) {
        cell.accessoryType=UITableViewCellAccessoryCheckmark;
    }
    
    return cell;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row==3) {
        NSLog(@"自定义铃声");
    }else{
        self.selectedMode=indexPath.row;
        [tableView reloadData];
    }
}

#pragma mark -
-(void)done
{
    [self.delegate alertModePickerViewController:self DidSelectedAlertMode:self.selectedMode];
    [self.navigationController popViewControllerAnimated:YES];
}

-(void)cancle
{
    [self.navigationController popViewControllerAnimated:YES];
}

@end
